<?php
session_start();
$error = $_SESSION['login_error'] ?? '';
unset($_SESSION['login_error']); // 清除已显示的错误
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Blog 系统</title>
    <link rel="stylesheet" type="text/css" href="CSS/index.css">
    <link rel="stylesheet" href="CSS/register.css" >
</head>
<body style="background-image: url('image/bg.png');background-size: cover; background-repeat: no-repeat; background-position: center;">
    <!-- 容器 -->
    <div class="container">

        <!-- 顶部导航栏 -->
        <div class="header">
            <div class="logo">
                <img src="image/log.png" alt="Logo" style="height: 25px;">
                <span style="margin-left: 20px;font-size: 25px;">我的博客</span>
            </div>
            <div >
                <a style="font-size: 15px;" href="#">主页</a>
            </div>
        </div>
        <!-- 顶部导航栏结束 -->
        <div class="parent">
            <div class="child">
                <div class="heade">
                    <span class="blog">Blog</span>
                </div>
                <form  class="form" action="registerold.php" method="post">
                    <p class="message">xiaohuai的博客 </p>
                    <div class="flex">
                        <label>
                            <input class="input" id="name" type="text" name="username"  placeholder="" required="">
                            <span>name*</span>
                        </label>
                        <!-- //空白字符 -->
                        <a>0 </a>
                        <label>
                            <input class="input" id="id" type="text" name="id" placeholder="" required="">
                            <span>id*</span>
                        </label>
                    </div>                  
                    <label>
                        <input class="input" id="password" type="password" name="password" placeholder="" required="">
                        <span>Password*</span>
                    </label>
                    <label>
                        <input class="input" id="password2" type="password" name="password2" placeholder="" required="">
                        <span>Confirm password*</span>
                    </label>
                    <label>
                        <input class="input" id="sex" type="text" name="sex" placeholder=""  required="">
                        <span>sex</span>
                    </label> 
                    <label>
                        <input class="input"id="phone" type="text" name="phone" placeholder=""  required="">
                        <span>phone</span>
                    </label> 
                    <label>
                        <input class="input" id="addr" type="text" name="addr" placeholder=""  required="">
                        <span><address>address</address></span>
                    </label> 
                    <?php if (!empty($error)): ?>
                        <div class="error_msg" id="regis_errorMsg"><?= $error ?></div>
                        <script src='script/autoHide.js'></script>
                        <script>
                            document.addEventListener('DOMContentLoaded', function() {
                                initAutoHide({ elementId: 'regis_errorMsg', delay: 3500 });
                                <?php if ($error === "注册成功"): ?>
                                    startCountdown('regis_errorMsg', 'blog_login.php',3,"登录");
                                <?php endif; ?>
                            });
                        </script>
                    <?php endif; ?>  
                    
                    <button  class="submit" type="submit" name="register">注册</button>
                    <p class="signin">Already have an acount ?
                        <a  type= "button" name="register"  value="register" rel="noopener noreferrer" onclick="window.location.href='blog_login.php'" class="">Sign up</a>
                    </p>
                </form>
            </div>
        </div>
    </div>
</body>
</html>